package com.lizhi.note.payload;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public class ResponseUtil {

    public static ResponseEntity<ApiResponse> success(Object data){
        return ResponseEntity.ok(ApiResponse.success(data));
    }

    public static ResponseEntity<ApiResponse> success(Object data, String message){
        return ResponseEntity.ok(ApiResponse.success(message, data));
    }

    public static ResponseEntity<ApiResponse> error(int code, String message) {
        return new ResponseEntity<>(ApiResponse.error(code, message), HttpStatus.valueOf(code));
    }

    /**
     * 失败响应（自定义数据，如验证错误详情）
     */
    public static <T> ResponseEntity<ApiResponse> error(int code, String message, T details) {
        return new ResponseEntity<>(ApiResponse.error(code, message, details), HttpStatus.valueOf(code));
    }

    /**
     * 系统异常响应（默认 500 错误）
     */
    public static ResponseEntity<ApiResponse> systemError(String message) {
        return error(500, "系统异常：" + message);
    }
}
